<?php

namespace app\teacher\model;

use app\common\model\BaseModel;
use think\Model;

class TeacherWithdraw extends BaseModel
{
    protected $autoWriteTimestamp = 'int';
    protected $createTime = 'createtime';
    protected $updateTime = 'updatetime';

    /**
     * 提现记录
     */
    public static function add($teacher, $data)
    {
        //手续费
        $fee = getSettingValue('withdraw_fee');
        $fee = 100 - $fee > 0 ? 100 - $fee : 0;
        $data = [
            'teacher_id' => $teacher->teacher_id,
            'money' => $data['money'],
            'real_money' => $data['money'] * $fee / 100,
            'before_money' => $teacher->money,
            'after_money' => $teacher->money - $data['money'],
            'username' => $data['username'] ?? '',
            'card_no' => $data['card_no'] ?? '',
            'card_name' => $data['card_name'] ?? '',
            'type' => $data['type']
        ];
        return self::insert($data);
    }

    /**
     * 提现记录
     */
    public static function getByTeacherId($teacherId, $size = 20)
    {
        return self::where('teacher_id', $teacherId)->order('createtime desc')->paginate($size);
    }
}
